var time=Math.floor(new Date().getTime()/1000);
var urs=window.location.search;
var strs=urs.substring(1);
var silp=strs.split('&');
var res={};
for (var i=0;i<silp.length;i++){
    res[silp[i].split("=")[0]]=silp[i].split("=")[1];
}
$("html,body").css("height",$(window).height());
console.log(res);
$.ajax({
    type : "GET",
    url : getRequestUrl("/user/get_message"),
    data:{
        user_id:res.id,
        page_size:100,
        page_num:1,
        timestamp:time
    },
    // contentType : "application/json",
    success : function(datas) {
        console.log(datas);
        //soll=true;
        var arr=datas.response_params.result;
        //pages=datas.response_params.total_cnt;
        var strs="";
        $.each(arr,function (i,el) {
            if(el.is_show_right=="1"){
                strs+=`<li>
                                <p class="date">`+gstime(el.insert_time)+`</p>
                                <div class="lybox">
                                    <img src=`+el.portrait+` data-id=`+el.user_id+` onclick="getuseInfo(this)">
                                    <div class="wz" >`+el.content+`<i></i></div>

                                </div>
                            </li>`
            }else{
                strs+=`<li>
                                <p class="date">`+gstime(el.insert_time)+`</p>
                                <div class="lybox fl">
                                    <img src=`+el.portrait+` class="fl" data-id=`+el.user_id+` onclick="getuseInfo(this)">
                                    <div class="wz fl">`+el.content+`<i></i></div>

                                </div>
                            </li>`
            }

        });
        $(strs).appendTo("#list");
        var h = $("#list").height()-$(window).height();
        $("body").scrollTop(h+100);
        $("#grtx").attr("src",localStorage.txurl);
        $("#loading").hide();

    },
    error : function(err) {
    	dealCPErrorResponse(err);
    }
});
function huida() {
    if($("#input").val()==""){
        return false
    }
    var timev=new Date().getTime()/1000;
    $.ajax({
        type : "POST",
        url : getRequestUrl("/user/add_message"),
        data:{
            passive_user_id:res.id,
            content:$("#input").val()
        },
        // contentType : "application/json",
        success : function(datas) {
            console.log(datas.response_params.result);
            if(datas.response_params.result=="0"){
                var sts=`<li>
                                <p class="date">`+gstime(timev)+`</p>
                                <div class="lybox">
                                    <img src=`+localStorage.txurl+`>
                                    <div class="wz">`+$("#input").val()+`<i></i></div>

                                </div>
                            </li> `;
                $(sts).appendTo("#list");
                var h = $("#list").height()-$(window).height();
                $("body").scrollTop(h+100);
                console.log($("#list").height());
                $("#input").val("")
            }
        },
        error : function(err) {
            if(err.responseJSON.error_code==31003){
                //$("#loading").hide();
                layer.open({
                    content: "您还未完成实名认证，完成实名认证即可享受更多免费福利哦~"
                    ,btn: ['认证去', '再看看']
                    ,yes: function(index){
                        window.location.href="Edit-information.html";
                        layer.close(index);
                    }
                });
                return false
            }
        	//dealCPErrorResponse(err);
        }
    });
}
function gstime(time) {
    var strs="";
    var date = new Date(time*1000);
    var y = date.getFullYear() + '-';
    var m = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
    var d = date.getDate() + ' ';
    var h = date.getHours()<10? '0'+date.getHours():date.getHours()+':';
    var s = date.getMinutes()<10? '0'+date.getMinutes():date.getMinutes();
    strs =y+m+d+h+s;
    return strs
}
function getuseInfo(obj) {
    var $this=$(obj);
    var id=$this.attr("data-id");
    window.location.href="Personal-information.html?userid="+id;
}